﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Threading;
using System.Net;
using System.Net.Sockets;
#endregion

namespace vlc
{
    /// <summary>
    /// This is the class that other applications will bind to, for the ease of examination.
    /// </summary>
    public class Network
    {
        public Thread myTcpThread;

        public Network()
        {}/*
            try
            {
                //Starting the TCP Listener thread.
                myTcpThread = new Thread(new ThreadStart(myServer.StartListen));
                myTcpThread.Start();
            }
            catch (Exception) { myTcpThread.Abort(); }
        }

        public Object networkCommunication(System.Net.IPEndPoint remotePeer, Byte[] toSend)
        {
            myByteSent += toSend.Length;
            try
            {
                //Create an instance of TcpClient. 
                TcpClient tcpClient = new TcpClient();
                tcpClient.Connect(remotePeer);
                NetworkStream tcpStream = tcpClient.GetStream();
                if (tcpStream.CanWrite)
                {
                    tcpStream.Write(toSend, 0, toSend.Length);
                    tcpStream.Flush();
                }
                if (tcpStream.CanRead)
                {
                    try
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        Object o = (Object)formatter.Deserialize(tcpStream);
                        //Begin counting received bytes.
                        System.IO.MemoryStream m = new System.IO.MemoryStream();
                        formatter.Serialize(m, o);
                        this.ByteReceived += m.Length;
                        //Done counting.
                        return o;
                    }
                    catch (Exception) { }
                }
                tcpStream.Close(0);
                tcpClient.Close();
            }
            catch (Exception) { }
            return null;
        }


        public string sendTCP(string s)
        {
           
        }
        */
    }
}
